დავით სიჭინავა, CRRC-საქართველო | თსუ
3 მაისი, 2019 წ.
ggplot2 ბიბლიოთეკა;ggplot2 და dplyr ბიბლიოთეკაlibrary(ggplot2) #ვიზუალიზაცია
library(dplyr) #მონაცემთა მანიპულირება
library(gapminder) #სავარჯიშო მონაცემები Gapminder-იდან
library(scales) #ბიბლიოთეკა მასშტაბის სწორად მისათითებლად
წყარო: socviz.co
წყარო: socviz.co
წყარო: socviz.co
წყარო: socviz.co
წყარო: socviz.co
ადამიანის თვალი მიდრეკილია, მონაცემებში გარკვეული კანონზომიერებები ,,დაინახოს'' იმის მიუხედავად, არსებობს თუ არა ეს კანონზომიერება
წყარო: socviz.co
წყარო: socviz.co
წყარო: menu.ge
წყარო: socviz.co
data(gapminder)
p <- ggplot(gapminder)
p
ggplot2 გარემოში ობიექტს წარმოადგენსaes() ფუნქციის მეშვეობით.p <- ggplot(data = gapminder,
mapping = aes(x = gdpPercap,
y = lifeExp))
p + geom_point()
წყარო: Wickham, 2010
წყარო: Wickham, 2010
position: პოზიცია,color: ,,გარეთა ფერი",fill: ,,შიდა ფერი",shape: მარკერების ფორმა,linetype: წრფის ტიპი,size: ზომაp <- ggplot(data = gapminder,
mapping = aes(x = gdpPercap,
y=lifeExp))
p + geom_point()+
geom_smooth()
p <- ggplot(data = gapminder,
mapping = aes(x = gdpPercap,
y=lifeExp))
p + geom_point()+
geom_smooth()+
scale_x_log10()
ggplot(gapminder,
aes(x = gdpPercap,
y=lifeExp))+
geom_point(aes(color=continent))+
geom_smooth()+
scale_x_log10()
ggplot(gapminder,
aes(x = gdpPercap,
y=lifeExp))+
geom_point(aes(color=pop))+
geom_smooth()+
scale_x_log10()
ggsave("gapminder_plot.png", device="png", height=5)
p <- ggplot(data = gapminder, mapping = aes(x = year, y = gdpPercap))
p + geom_line(color="gray70", aes(group = country)) +
geom_smooth(size = 1.1, method = "loess", se = FALSE) +
scale_y_log10(labels=scales::dollar) +
facet_wrap(~ continent, ncol = 5) +
labs(x = "Year",
y = "GDP per capita",
title = "GDP per capita on Five Continents")
havenndi <- haven::read_dta("NDI_2018_Jun_16.07.18_Public.dta")
table(ndi$PARTYSUPP1)
prop.table(table(ndi$PARTYSUPP1))
dplyr ბიბლიოთეკა გამოგვადგებაparty <- ndi %>%
mutate(party = case_when(
PARTYSUPP1 == 8 ~ 1,
PARTYSUPP1 == 6 ~ 2,
PARTYSUPP1 == 7 ~ 3,
PARTYSUPP1 == -1 ~ 5,
PARTYSUPP1 == -2 ~ 6,
PARTYSUPP1 == 25 ~ 7,
TRUE ~ 4
)) %>%
count(., party, wt = WTIND) %>%
mutate(n/sum(n))
names(party) <- c("party", "frequency", "proportion")
party$party <- factor(party$party, levels=c(1, 2, 3, 4, 5, 6, 7),
labels=c("GD", "UNM", "MLEG", "Other",
"DK", "RA", "None"))
ggplot(party, aes(party, proportion))+
geom_bar(stat="identity")
party.settype <- ndi %>%
mutate(party = case_when(
PARTYSUPP1 == 8 ~ 1,
PARTYSUPP1 == 6 ~ 2,
PARTYSUPP1 == 7 ~ 3,
PARTYSUPP1 == -1 ~ 5,
PARTYSUPP1 == -2 ~ 6,
PARTYSUPP1 == 25 ~ 7,
PARTYSUPP1 < -2 ~ NA_real_,
TRUE ~ 4
)) %>%
group_by(STRATUM)%>%
count(., party, wt = WTIND) %>%
mutate(n/sum(n))
names(party.settype) <- c("settlement", "party", "frequency", "proportion")
party.settype$party <- factor(party.settype$party, levels=c(1, 2, 3, 4, 5, 6, 7),
labels=c("ოცნება", "ენმ", "ესმთ", "სხვა",
"არ ვიცი", "უარი", "სხვა"))
party.settype$settlement <- factor(party.settype$settlement, levels=c(1, 2, 3, 4, 5),
labels=c("თბილისი", "დიდი ქალაქი", "პატარა ქალაქი", "სოფელი", "ეთნ. უმცირესობები"))
ggplot(party.settype, aes(party, proportion))+
geom_bar(aes(fill=party),stat="identity")+
scale_fill_manual(values=c("#1f78b4", "#e31a1c", "#a6cee3", "#b2df8a", "#444444", "#999999", "#fb9a99"))+
ylim(0, 1)+
labs(title="რომელი პარტია დგას თქვენს შეხედულებებთან ყველაზე ახლოს?",
subtitle="დასახლებული პუნქტის ტიპის მიხედვით")+
theme_bw()+
theme(legend.position = "none")+
facet_grid(~settlement)
ggplot2 ,,შპარგალკა''Kieran Healy: Data Visualization - A practical introduction Selva Prabhakaran: How to make any plot in ggplot2? Ista Zahn: R graphics workshop @ Harvard